package Frame.battleanimation;

import FCRendering.FCRMaster;
import VWorldGameStudio.FCMonster;

import java.awt.*;

import static FCRendering.FCRMaster.fcv;
//逃跑动画
public class MsEscapeAni extends ABattleAni {

    FCMonster monster;


    int goFrame = 0;
    int[] startPoint = new int[2];
    int[] paintPoint = new int[2];
    Integer[] s;
    private int[] moveEndPoint = new int[2];

    public MsEscapeAni(FCMonster monster) {
        this.monster = monster;

        s = fcv.getBattleMonsterCoor().get(fcv.getBattleMonster().indexOf(monster));

        moveEndPoint[0] = -s[2] - 40;
        moveEndPoint[1] = s[1];

        startPoint[0] = s[0];
        startPoint[1] = s[1];
        //STEP 1计算俩点之间距离，速度假设是v像素/毫秒，
        int v = (int) (600 * fcv.getProportion());
        double targetDistance = AnimationUtil.getDistance(startPoint, moveEndPoint);
        goFrame = (int) (16 * targetDistance / v);

        allFrames = goFrame;
    }

    @Override
    public void nextFrame(int frame) {
        AnimationUtil.getAnimatePoint(paintPoint, startPoint, moveEndPoint, (float) (frame) / allFrames);
        s[0] = paintPoint[0];
        s[1] = paintPoint[1];
        if(frame == allFrames) {
            //TODO 一定要回归原位，因为呼叫同伴有需要用到旧的位置
            monster.setShowInBattle(false);
            s[0] = startPoint[0];
            s[1] = startPoint[1];
        }
    }

    @Override
    public void paintBattleSceen(Graphics g, FCRMaster fcrMaster) {

    }
}
